<template>
  <div class="tm-color-list">
    <div class="list-span"
         v-for="(item, index) in currValue"
         :key="index">
      <el-color-picker v-model="item[0]" show-alpha></el-color-picker>
      <el-color-picker v-model="item[1]" show-alpha></el-color-picker>
      <el-color-picker v-model="item[2]" show-alpha></el-color-picker>
      <div class="list-remove" @click="onRemove(index)">
        <i class="el-icon-delete"></i>
      </div>
    </div>
    <div class="list-add">
     新增颜色:
      <div class="list-add-item" @click="onAdd">
        <i class="el-icon-plus"></i>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'tm-color-list',
  cnName: '渐变颜色列表',
  props: {
    value: Array
  },
  data() {
    return {
      currValue: this.value
    }
  },
  methods: {
    onAdd() {
      this.currValue.push(['#fff', '#00FFDD', '#00C3FF'])
      this.$emit('input', this.currValue)
    },
    onRemove(index) {
      this.currValue.splice(index, 1)
      this.$emit('input', this.currValue)
    }
  },
  watch: {
    value(nval) {
      this.currValue = nval
    }
  }
}
</script>

<style lang="less" scoped>
.tm-color-list {
  .list-span {
    width: 100%;
    height: 30px;
    display: flex;
    margin-bottom: 5px;
    align-items: center;
  }
  .list-remove {
    margin-left: 10px;
    display: flex;
    align-items: center;
    color: var(--text-color);
    cursor: pointer;
  }
  .list-add {
    display: flex;
    align-items: center;
    color: var(--text-color);

    &-item {
      margin-left: 10px;
      border: 1px solid var(--bd-color);
      color: var(--text-color);
    }
  }
}
</style>
